<?php
if (Yii::app()->request->isAjaxRequest) {
    Yii::app()->clientscript->scriptMap['jquery.js'] = false;
    Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;
}
?>


<?php
$this->menu=array(
//	array('label'=>Yii::t('application', 'List {title}', array('{title}'=>Yii::t('application', 'Transactionmaster'))), 'url'=>array('index')),
	array('label'=>Yii::t('application', 'Create {title}', array('{title}'=>Yii::t('application', 'Transactionmaster'))), 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.transactionmaster-search-button').click(function(){
	$('.transactionmaster-search-form').toggle();
	return false;
});
$('.transactionmaster-search-form form').submit(function(){
	$.fn.yiiGridView.update('transactionmaster-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<?php echo CHtml::link(Yii::t('application', 'Advanced Search'),'#',array('class'=>'Transactionmaster-search-button')); ?>
<div class="transactionmaster-search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->


<?php
//$items = array(
//    array('label'=>'Home', 'url'=>array('/site/index')),
//    array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
//    array('label'=>'Contact', 'url'=>array('/site/contact')),
//    array('label'=>'Products', 'url'=>'#', 'items'=>array(
//        array('label'=>'Web', 'url'=>'#', 'items'=>array(
//            array('label'=>'NLSClientScript', 'url'=>array('/site/page', 'view'=>'nlsclientscript')),
//            array('label'=>'EFgMenu', 'url'=>array('/site/page', 'view'=>'efgmenu')),
//            array('label'=>'XCruder', 'url'=>'#')
//        )),
//        array('label'=>'Desktop', 'url'=>'#', 'items'=>array(
//            array('label'=>'BatchReplacePro', 'url'=>'#'),
//            array('label'=>'DeformerPro', 'url'=>'#')
//        ))
//    ))
//);
 
//$this->widget('ext.efgmenu.EFgMenu',array(
//    'bDev'=>true,
//    'id'=>'simpleMenu',
////    'theme' => 'bgscstpc',
//    'trigger'=>'#bSimple',
//    'items'=>$items,
//    'menuOptions' => array(
//        'flyOut'=>true
//    )
//));
?>
<!--<select onchange='alert($(this).val()); <?php echo 'add_tab("accountingvoucher", "' . CController::createUrl('transactionmaster/accountingvouchers', array('isAjaxRequest' => 1, 'idtransactionmaster'=>5)) . '", "' . Yii::t('application', 'Accountingvoucher') . '");'; ?>'>
    <option>Accounting Vouchers</option>
    <option><a href="">Contra</a> </option>
    <option>Accounting Vouchers2</option>
    <option>Accounting Vouchers3</option>
</select>-->

<?php
//    echo CHtml::dropDownList('', '', 
//            $model->getVouchertypeArray(),
//                array(
//                    'empty' => 'Accounting Vouchers',
////                    'onchange' => 'alert($(this).val());',
//                    'onchange' => 
//                                            '$.ajax({
//                          url: "'.Yii::app()->createUrl('transactionmaster/init').'&isAjaxRequest=1",
//                          success: function(data){
//                             return false;
//                          }
//                        });' .
//                    'add_tab("accountingvoucher", "' . CController::createUrl('transactionmaster/accountingvouchers', array('isAjaxRequest' => 1, 'idtransactionmaster'=>0)) . '&idvouchertype="+$(this).val(), "' . Yii::t('application', 'Accountingvoucher') . '");',
//                )            
//            );
?>

<?php

$pagertoolbox = '';
$pagertoolbox .= "<table border='0'>";
$pagertoolbox .= "<tr>";
$pagertoolbox .= "<td>";
$pagertoolbox .= CHtml::link(
        "<div class='ui-pg-div'><span class='ui-icon ui-icon-refresh'></span></div>", 
        "#", 
        $htmlOptions = array(
            'title'=>Yii::t('application', 'Reload'),
            'onclick' => '$.fn.yiiGridView.update("transactionmaster-grid", {
		data: $(this).serialize()
            });'
            ));
$pagertoolbox .= "</td>";
$pagertoolbox .= "<td>";
$pagertoolbox .= CHtml::link(
                "<div class='ui-pg-div'><span class='ui-icon ui-icon-plus'></span></div>", 
                "#", 
                $htmlOptions = array(
                    'title'=>Yii::t('application', 'New'),
                    'onclick' => '
                        $.ajax({
                          url: "'.Yii::app()->createUrl('transactionmaster/init').'&isAjaxRequest=1",
                          success: function(data){
                             return false;
                          }
                        });
//                        $.ajax({
//                          url: "'.Yii::app()->createUrl('transactionmaster/create').'&isAjaxRequest=1",
//                          success: function(data){
//                             $("#dialog").html(data);
//                             $("#dialog").dialog("option", "title", "'. Yii::t('application', 'Create {title}', array('{title}'=>Yii::t('application', 'Transactionmaster'))) .'");
//                             $("#dialog").dialog("option", "height", "auto");
//                             $("#dialog").dialog("option", "width", "auto");
//                             $("#dialog").dialog("open"); 
//                             return false;
//                          }
//                        });
                        ' . 
                    'add_tab("accountingvoucher", "' . CController::createUrl('transactionmaster/accountingvouchers', array('isAjaxRequest' => 1, 'idtransactionmaster'=>5)) . '", "' . Yii::t('application', 'Accountingvoucher') . '");'                    ,
                'sytle' => ''
                )
);$pagertoolbox .= "</td>";
$pagertoolbox .= "<td>";
$pagertoolbox .= CHtml::link(
                "<div class='ui-pg-div'><span class='ui-icon ui-icon-pencil'></span></div>", 
                "#", 
                $htmlOptions = array(
                    'onclick' => '
                          if($.fn.yiiGridView.getSelection("transactionmaster-grid") != ""){
                        $.ajax({
                          url: "'.Yii::app()->createUrl('transactionmaster/init').'&isAjaxRequest=1",
                          success: function(data){
                             return false;
                          }
                        });
                               add_tab("accountingvoucher", "' . CController::createUrl('transactionmaster/accountingvouchers', array('isAjaxRequest' => 1)) . '&idtransactionmaster=" + $.fn.yiiGridView.getSelection("transactionmaster-grid") +"&idvouchertype=-1", "' . Yii::t('application', 'Accountingvoucher') . ' - " + window.vouchertype);
                                   window.vouchertype = "";
//                                $.ajax({
//                                  url: "'.Yii::app()->createUrl('transactionmaster/update').'&isAjaxRequest=1&id=" + $.fn.yiiGridView.getSelection("transactionmaster-grid"),
//                                  success: function(data){
//                                     $("#dialog").html(data);
//                                     $("#dialog").dialog("option", "title", "'. Yii::t('application','Update {title}', array('{title}'=>Yii::t('application', 'Transactionmaster'))) .' - " + $.fn.yiiGridView.getSelection("transactionmaster-grid"));
//                                     $("#dialog").dialog("option", "height", "auto");
//                                     $("#dialog").dialog("option", "width", "auto");
//                                     $("#dialog").dialog("open"); 
//                                     return false;
//                                  }
//                                });
                           }
                           else{
                                $("#dialog-warning-msg").html("'. Yii::t('application','Please, select row...') .'"); $("#dialog-warning").dialog("open"); return false;
                           }             
                        ',
                )
);
$pagertoolbox .= "</td>";
$pagertoolbox .= "<td>";
$pagertoolbox .= CHtml::link("<div class='ui-pg-div'><span class='ui-icon ui-icon-trash'></span></div>", '#', array(
            'title'=>Yii::t('application', 'Delete'),
            'onclick'=>'
                    if($.fn.yiiGridView.getSelection("transactionmaster-grid") != ""){
                        window.cid = "transactionmaster";
                        window.url = "'. CController::createUrl('transactionmaster/delete').'";
                        $("#dialog-delete").dialog("open"); 
                        return false;
                    }
                   else{
                        $("#dialog-warning-msg").html("'. Yii::t('application','Please, select row...') .'"); 
                        $("#dialog-warning").dialog("open"); 
                        return false;
                   }                       
                ',
    ));
$pagertoolbox .= "</td>";
$pagertoolbox .= "<td>";
$pagertoolbox .= CHtml::link(
                "<div class='ui-pg-div'><span class='ui-icon ui-icon-search'></span></div>", 
                "#", 
                $htmlOptions = array(
                    'onclick' => '
                        if($.fn.yiiGridView.getSelection("transactionmaster-grid") != ""){
                            $.ajax({
                              url: "'.Yii::app()->createUrl('transactionmaster/view').'&isAjaxRequest=1&id=" + $.fn.yiiGridView.getSelection("transactionmaster-grid"),
                              success: function(data){
                                $("#dialog").html(data);
                                $("#dialog").dialog("option", "title", "'. Yii::t('application','View {title}', array('{title}'=>Yii::t('application', 'Transactionmaster'))) .' - " + $.fn.yiiGridView.getSelection("transactionmaster-grid"));
                                $("#dialog").dialog("option", "height", "auto");
                                $("#dialog").dialog("option", "width", "auto");
                                $("#dialog").dialog("open"); 
                                return false;
                              }
                            });                        
                        }
                        else{
                            $("#dialog-warning-msg").html("'. Yii::t('application','Please, select row...') .'"); 
                            $("#dialog-warning").dialog("open"); 
                            return false;
                        }
                        ',
                'sytle' => ''
                )
);
$pagertoolbox .= "</td>";
$pagertoolbox .= "<td>";
$pagertoolbox .= CHtml::dropDownList('', '', 
            $model->getVouchertypeArray(),
                array(
                    'id' => 'newvoucherselect',
                    'empty' => 'New Vouchers',
                    'style' => ' font-family: Verdana,Arial,sans-serif; font-size: .65em;',
//                    'onchange' => 'alert($(this).val());',
                    'onchange' => 
                          '$.ajax({
                          url: "'.Yii::app()->createUrl('transactionmaster/init').'&isAjaxRequest=1",
                          success: function(data){
                             return false;
                          }
                        });                         
                        selectedId = $(this).val();
                        selectedText = $(this).find("option:selected").text();
                        //alert(selectedText);
                        $(this).val("");
                        ' .
//                    'alert("'.CController::createUrl('transactionmaster/accountingvouchers', array('isAjaxRequest' => 1, 'idtransactionmaster'=>0)). '&idvouchertype="+selectedId, "' . Yii::t('application', 'Accountingvoucher') . '");' .
                    'add_tab("accountingvoucher", "' . CController::createUrl('transactionmaster/accountingvouchers', array('isAjaxRequest' => 1, 'idtransactionmaster'=>0)) . '&idvouchertype="+selectedId, "' . Yii::t('application', 'Accountingvoucher') . ' - " + selectedText);
                        //  $("#newvoucherselect option:first-child").attr("selected", "selected");
                           
                        
                    ',
                )            
            );
$pagertoolbox .= "</td>";
$pagertoolbox .= "</tr>";
$pagertoolbox .= "</table>";
?> 

<?php $this->widget('ext.eziiui.widgets.grid.CGridViewUI', array(
	'id'=>'transactionmaster-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
        'ajaxVar' => 'ajax',
        'selectionChanged'=>'function(id){onSelectionChangeTransactionmasterGrid()}',
        "template" => "{summary}{items}<div class='ui-widget-header ui-corner-bottom' style='width:100%; float:left;'><div style='float:left;'>" .
        $pagertoolbox .
        "</div>{pager}</div>",        
	'columns'=>array(
		array(
			'class'=>'CCheckBoxColumn',
		),
		'idtransactionmaster',
		'transactionmastervoucherdate',
		'transactionmasternarration',
                array(
                    'name'=>'idvouchertype',
                    'value'=>'$data->idvouchertype0->vouchertype',
                    'filter' => $model->getVouchertypeArray(),
                ),
		
	),
)); ?>

<script type="text/javascript">
    function onSelectionChangeTransactionmasterGrid()
    {

            $("#transactionmaster-grid > table > tbody > tr").each(function(i)
            {
                    if($(this).hasClass("selected"))
                    {
                        window.vouchertype = $(this).children(":nth-child(5)").text();
                        //alert($(this).children(":nth-child(4)").text());
                    }
                    else{
                        //$("#id").val('-1');                        
                    }
            });
    }    
</script>        
